import { createStore } from 'vuex';
import{getPhoneLogin}from'../api/home/api';
import {getMusicLyric} from "../api/home/item"
export default createStore({
    state: {
        playList: [{
            al: {//播放列表添加一个默认值
               id
               : 
               71783637,
               name
               : 
               "若把你",
               pic
               : 
               109951163401482430,
               picUrl
               : 
               "http://p4.music.126.net/M877M2-VhWZiLPVFORf9iQ==/109951163401482434.jpg",
               pic_str
               : 
               "109951163401482434"
            },
            id:865632948,
            name
               : 
               "若把你",
            ar:[{
               name: 'Kirsty刘瑾睿'
            }]
        }],
        playListIndex: 0,//默认下标为0
        isbtnShow:true,//暂停按钮显示
        detailShow:false,//歌曲详情页展示
        isLogin:false,//是否登录
        isFooterMusic:true,//判断是否显示底部
        token: "",
        user:{},//用户信息
        LyricList:{},
        currentTime:0,//当前时间
       duration:0,//歌曲时长
    },
    mutations: {
     updateIsbtnShow:function(state,value){
        state.isbtnShow=value
     },
     //切换歌曲
     updatePlayList:function(state,value){
        state.playList=value
        console.log(state.playList);
     },
     updatePlayListIndex:function(state,value){
        state.playListIndex=value

     },
    pushPlayList:function(state,value){
         // state.playListIndex=value
         state.playList.push(value)
         // console.log(state.playListIndex);
         },
     updateDetailShow:function(state){
        state.detailShow=!state.detailShow;
     },
     updateIsLogin:function(state,value){
        state.isLogin=true 
     },
     updateToken:function(state,value){
        state.token=value
        localStorage.setItem('token',state.token)
     },
     updateUser:function(state,value){
        state.user=value
     },
     updateLyricList:function(state,value){
      state.LyricList=value
     },
     updateCurrentTime:function(state,value){
      state.currentTime=value
     },
     updateDuration:function(state,value){
      state.duration=value
     }
    },
    actions: {
    getLogin:async function(context,value){
        let res=await getPhoneLogin(value);
        return res
    },
      getLyric: async function(context,value){
         let res = await getMusicLyric(value)
         console.log(res); 
         context.commit("updateLyricList",res.data.lrc)
      }
    },
    modules: {

    }
})